home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / APPLICAT.C < prev    next >
Text File  |  1992-08-11  |  21KB  |  726 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static int ScreenHeight;
  6. static BOOL AltDown = FALSE;
  7. static BOOL DisplayModified = FALSE;
  8. WINDOW ApplicationWindow;
  9.  
  10. extern DBOX Display;
  11. extern DBOX Windows;
  12.  
  13. #ifdef INCLUDE_LOGGING
  14. extern DBOX Log;
  15. #endif
  16.  
  17. #ifdef INCLUDE_SHELLDOS
  18. static void ShellDOS(WINDOW);
  19. #endif
  20. static void CreateMenu(WINDOW);
  21. static void CreateStatusBar(WINDOW);
  22. static void SelectColors(WINDOW);
  23. static void SetScreenHeight(int);
  24. static void SelectLines(WINDOW);
  25.  
  26. #ifdef INCLUDE_WINDOWOPTIONS
  27. static void SelectTexture(void);
  28. static void SelectBorder(WINDOW);
  29. static void SelectTitle(WINDOW);
  30. static void SelectStatusBar(WINDOW);
  31. #endif
  32.  
  33. static WINDOW oldFocus;
  34. #ifdef INCLUDE_MULTI_WINDOWS
  35. static void CloseAll(WINDOW, int);
  36. static void MoreWindows(WINDOW);
  37. static void ChooseWindow(WINDOW, int);
  38. static int WindowSel;
  39. static char *Menus[9] = {
  40.     "~1.                      ",
  41.     "~2.                      ",
  42.     "~3.                      ",
  43.     "~4.                      ",
  44.     "~5.                      ",
  45.     "~6.                      ",
  46.     "~7.                      ",
  47.     "~8.                      ",
  48.     "~9.                      "
  49. };
  50. #endif
  51.  
  52. /* --------------- CREATE_WINDOW Message -------------- */
  53. static int CreateWindowMsg(WINDOW wnd)
  54. {
  55.     int rtn;
  56.     ApplicationWindow = wnd;
  57.     ScreenHeight = SCREENHEIGHT;
  58.     if (!DisplayModified)    {
  59.            int i;
  60.            CTLWINDOW *ct, *ct1;
  61.            ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  62.         if (!isVGA())    {
  63.             /* ---- modify Display Dialog Box for EGA, CGA ---- */
  64.             if (isEGA())
  65.                 ct1 = FindCommand(&Display,ID_50LINES,RADIOBUTTON);
  66.             else    {
  67.                 CTLWINDOW *ct2;
  68.                 ct2 = FindCommand(&Display,ID_COLOR,RADIOBUTTON)-1;
  69.                 ct2->dwnd.w++;
  70.                 for (i = 0; i < 7; i++)
  71.                     (ct2+i)->dwnd.x += 8;
  72.                 ct1 = FindCommand(&Display,ID_25LINES,RADIOBUTTON)-1;
  73.             }
  74.             for (i = 0; i < 6; i++)
  75.                 *ct1++ = *ct++;
  76.         }
  77.         if (isVGA() || isEGA())    {
  78.             /* ------ eliminate the snowy check box ----- */
  79.                ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  80.             if (ct != NULL)
  81.                 for (i = 0; i < 4; i++)
  82.                     *(ct+i) = *(ct+2+i);
  83.         }
  84.         DisplayModified = TRUE;
  85.     }
  86. #ifdef INCLUDE_WINDOWOPTIONS
  87.     if (cfg.Border)
  88.         SetCheckBox(&Display, ID_BORDER);
  89.     if (cfg.Title)
  90.         SetCheckBox(&Display, ID_TITLE);
  91.     if (cfg.StatusBar)
  92.         SetCheckBox(&Display, ID_STATUSBAR);
  93.     if (cfg.Texture)
  94.         SetCheckBox(&Display, ID_TEXTURE);
  95. #endif
  96.     if (cfg.mono == 1)
  97.         PushRadioButton(&Display, ID_MONO);
  98.     else if (cfg.mono == 2)
  99.         PushRadioButton(&Display, ID_REVERSE);
  100.     else
  101.         PushRadioButton(&Display, ID_COLOR);
  102.     if (cfg.ScreenLines == 25)
  103.         PushRadioButton(&Display, ID_25LINES);
  104.     else if (cfg.ScreenLines == 43)
  105.         PushRadioButton(&Display, ID_43LINES);
  106.     else if (cfg.ScreenLines == 50)
  107.         PushRadioButton(&Display, ID_50LINES);
  108.     if (cfg.snowy)
  109.         SetCheckBox(&Display, ID_SNOWY);
  110.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  111.         SetScreenHeight(cfg.ScreenLines);
  112.         if (WindowHeight(wnd) == ScreenHeight ||
  113.                 SCREENHEIGHT-1 < GetBottom(wnd))    {
  114.             WindowHeight(wnd) = SCREENHEIGHT-1;
  115.             GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd)-1;
  116.             wnd->RestoredRC = WindowRect(wnd);
  117.         }
  118.     }
  119.     SelectColors(wnd);
  120. #ifdef INCLUDE_WINDOWOPTIONS
  121.     SelectBorder(wnd);
  122.     SelectTitle(wnd);
  123.     SelectStatusBar(wnd);
  124. #endif
  125.     rtn = BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
  126.     if (wnd->extension != NULL)
  127.         CreateMenu(wnd);
  128.     CreateStatusBar(wnd);
  129.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  130.     return rtn;
  131. }
  132.  
  133. /* --------- ADDSTATUS Message ---------- */
  134. static void AddStatusMsg(WINDOW wnd, PARAM p1)
  135. {
  136.     if (wnd->StatusBar != NULL)    {
  137.         if (p1 && *(char *)p1)
  138.             SendMessage(wnd->StatusBar, SETTEXT, p1, 0);
  139.         else 
  140.             SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  141.         SendMessage(wnd->StatusBar, PAINT, 0, 0);
  142.     }
  143. }
  144.  
  145. /* -------- SETFOCUS Message -------- */
  146. static void SetFocusMsg(WINDOW wnd, BOOL p1)
  147. {
  148.     if (p1)
  149.         SendMessage(inFocus, SETFOCUS, FALSE, 0);
  150.     inFocus = p1 ? wnd : NULL;
  151.     if (isVisible(wnd))
  152.         SendMessage(wnd, BORDER, 0, 0);
  153.     else 
  154.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  155. }
  156.  
  157. /* ------- SIZE Message -------- */
  158. static void SizeMsg(WINDOW wnd, PARAM p1, PARAM p2)
  159. {
  160.     BOOL WasVisible;
  161.     WasVisible = isVisible(wnd);
  162.     if (WasVisible)
  163.         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  164.     if (p1-GetLeft(wnd) < 30)
  165.         p1 = GetLeft(wnd) + 30;
  166.     BaseWndProc(APPLICATION, wnd, SIZE, p1, p2);
  167.     CreateMenu(wnd);
  168.     CreateStatusBar(wnd);
  169.     if (WasVisible)
  170.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  171. }
  172.  
  173. /* ----------- KEYBOARD Message ------------ */
  174. static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
  175. {
  176.     AltDown = FALSE;
  177.     if (WindowMoving || WindowSizing || (int) p1 == F1)
  178.         return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
  179.     switch ((int) p1)    {
  180.         case ALT_F4:
  181.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  182.             return TRUE;
  183. #ifdef INCLUDE_MULTI_WINDOWS
  184.         case ALT_F6:
  185.             SetNextFocus();
  186.             return TRUE;
  187. #endif
  188.         case ALT_HYPHEN:
  189.             BuildSystemMenu(wnd);
  190.             return TRUE;
  191.         default:
  192.             break;
  193.     }
  194.     PostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
  195.     return TRUE;
  196. }
  197.  
  198. /* --------- SHIFT_CHANGED Message -------- */
  199. static void ShiftChangedMsg(WINDOW wnd, PARAM p1)
  200. {
  201.     if ((int)p1 & ALTKEY)
  202.         AltDown = TRUE;
  203.     else if (AltDown)    {
  204.         AltDown = FALSE;
  205.         if (wnd->MenuBarWnd != inFocus)
  206.             SendMessage(NULL, HIDE_CURSOR, 0, 0);
  207.         SendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
  208.     }
  209. }
  210.  
  211. /* -------- COMMAND Message ------- */
  212. static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
  213. {
  214.     switch ((int)p1)    {
  215.         case ID_HELP:
  216.             DisplayHelp(wnd, DFlatApplication);
  217.             break;
  218.         case ID_HELPHELP:
  219.             DisplayHelp(wnd, "HelpHelp");
  220.             break;
  221.         case ID_EXTHELP:
  222.             DisplayHelp(wnd, "ExtHelp");
  223.             break;
  224.         case ID_KEYSHELP:
  225.             DisplayHelp(wnd, "KeysHelp");
  226.             break;
  227.         case ID_HELPINDEX:
  228.             DisplayHelp(wnd, "HelpIndex");
  229.             break;
  230. #ifdef TESTING_DFLAT
  231.         case ID_LOADHELP:
  232.             LoadHelpFile();
  233.             break;
  234. #endif
  235. #ifdef INCLUDE_LOGGING
  236.         case ID_LOG:
  237.             MessageLog(wnd);
  238.             break;
  239. #endif
  240. #ifdef INCLUDE_SHELLDOS
  241.         case ID_DOS:
  242.             ShellDOS(wnd);
  243.             break;
  244. #endif
  245.         case ID_EXIT:
  246.         case ID_SYSCLOSE:
  247.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  248.             break;
  249.         case ID_DISPLAY:
  250.             if (DialogBox(wnd, &Display, TRUE, NULL))    {
  251.                 if (inFocus == wnd->MenuBarWnd || inFocus == wnd->StatusBar)
  252.                     oldFocus = ApplicationWindow;
  253.                 else 
  254.                     oldFocus = inFocus;
  255.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  256.                 SelectColors(wnd);
  257.                 SelectLines(wnd);
  258. #ifdef INCLUDE_WINDOWOPTIONS
  259.                 SelectBorder(wnd);
  260.                 SelectTitle(wnd);
  261.                 SelectStatusBar(wnd);
  262.                 SelectTexture();
  263. #endif
  264.                 CreateMenu(wnd);
  265.                 CreateStatusBar(wnd);
  266.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  267.                 SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  268.             }
  269.             break;
  270.         case ID_SAVEOPTIONS:
  271.             SaveConfig();
  272.             break;
  273. #ifdef INCLUDE_MULTI_WINDOWS
  274.         case ID_WINDOW:
  275.             ChooseWindow(wnd, (int)p2-2);
  276.             break;
  277.         case ID_CLOSEALL:
  278.             CloseAll(wnd, FALSE);
  279.             break;
  280.         case ID_MOREWINDOWS:
  281.             MoreWindows(wnd);
  282.             break;
  283. #endif
  284. #ifdef INCLUDE_RESTORE
  285.         case ID_SYSRESTORE:
  286. #endif
  287.         case ID_SYSMOVE:
  288.         case ID_SYSSIZE:
  289. #ifdef INCLUDE_MINIMIZE
  290.         case ID_SYSMINIMIZE:
  291. #endif
  292. #ifdef INCLUDE_MAXIMIZE
  293.         case ID_SYSMAXIMIZE:
  294. #endif
  295.             BaseWndProc(APPLICATION, wnd, COMMAND, p1, p2);
  296.             break;
  297.         default:
  298.             if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
  299.                 PostMessage(inFocus, COMMAND, p1, p2);
  300.             break;
  301.     }
  302. }
  303.  
  304. /* --------- CLOSE_WINDOW Message -------- */
  305. static int CloseWindowMsg(WINDOW wnd)
  306. {
  307.     int rtn;
  308. #ifdef INCLUDE_MULTI_WINDOWS
  309.     CloseAll(wnd, TRUE);
  310. #endif
  311.     PostMessage(NULL, STOP, 0, 0);
  312.     rtn = BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
  313.     if (ScreenHeight != SCREENHEIGHT)
  314.         SetScreenHeight(ScreenHeight);
  315.     UnLoadHelpFile();
  316.     DisplayModified = FALSE;
  317.     AltDown = FALSE;
  318.     WindowSel = 0;
  319.     ApplicationWindow = NULL;
  320.     return rtn;
  321. }
  322.  
  323. /* --- APPLICATION Window Class window processing module --- */
  324. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  325. {
  326.     switch (msg)    {
  327.         case CREATE_WINDOW:
  328.             return CreateWindowMsg(wnd);
  329.         case HIDE_WINDOW:
  330.             if (wnd == inFocus)
  331.                 inFocus = NULL;
  332.             break;
  333.         case ADDSTATUS:
  334.             AddStatusMsg(wnd, p1);
  335.             return TRUE;
  336.         case SETFOCUS:
  337.             if ((int)p1 == (inFocus != wnd))    {
  338.                 SetFocusMsg(wnd, (BOOL) p1);
  339.                 return TRUE;
  340.             }
  341.             break;
  342.         case SIZE:
  343.             SizeMsg(wnd, p1, p2);
  344.             return TRUE;
  345. #ifdef INCLUDE_MINIMIZE
  346.         case MINIMIZE:
  347.             return TRUE;
  348. #endif
  349.         case KEYBOARD:
  350.             return KeyboardMsg(wnd, p1, p2);
  351.         case SHIFT_CHANGED:
  352.             ShiftChangedMsg(wnd, p1);
  353.             return TRUE;
  354.         case PAINT:
  355.             if (isVisible(wnd))    {
  356. #ifdef INCLUDE_WINDOWOPTIONS
  357.                 int cl = cfg.Texture ? APPLCHAR : ' ';
  358. #else
  359.                 int cl = APPLCHAR;
  360. #endif
  361.                 ClearWindow(wnd, (RECT *)p1, cl);
  362.             }
  363.             return TRUE;
  364.         case COMMAND:
  365.             CommandMsg(wnd, p1, p2);
  366.             return TRUE;
  367.         case CLOSE_WINDOW:
  368.             return CloseWindowMsg(wnd);
  369.         default:
  370.             break;
  371.     }
  372.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  373. }
  374.  
  375. #ifdef INCLUDE_SHELLDOS
  376. static void SwitchCursor(void)
  377. {
  378.     SendMessage(NULL, SAVE_CURSOR, 0, 0);
  379.     SwapCursorStack();
  380.     SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  381. }
  382.  
  383. /* ------- Shell out to DOS ---------- */
  384. static void ShellDOS(WINDOW wnd)
  385. {
  386.     oldFocus = inFocus;
  387.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  388.     SwitchCursor();
  389.     if (ScreenHeight != SCREENHEIGHT)
  390.         SetScreenHeight(ScreenHeight);
  391.     SendMessage(NULL, HIDE_MOUSE, 0, 0);
  392.     printf("To return to %s, execute the DOS exit command.",
  393.                     DFlatApplication);
  394.     fflush(stdout);
  395.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  396.     if (SCREENHEIGHT != cfg.ScreenLines)
  397.         SetScreenHeight(cfg.ScreenLines);
  398.     SwitchCursor();
  399.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  400.     SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  401.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  402. }
  403. #endif
  404.  
  405. /* -------- Create the menu bar -------- */
  406. static void CreateMenu(WINDOW wnd)
  407. {
  408.     AddAttribute(wnd, HASMENUBAR);
  409.     if (wnd->MenuBarWnd != NULL)
  410.         SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
  411.     wnd->MenuBarWnd = CreateWindow(MENUBAR,
  412.                         NULL,
  413.                         GetClientLeft(wnd),
  414.                         GetClientTop(wnd)-1,
  415.                         1,
  416.                         ClientWidth(wnd),
  417.                         NULL,
  418.                         wnd,
  419.                         NULL,
  420.                         0);
  421.     SendMessage(wnd->MenuBarWnd,BUILDMENU,
  422.         (PARAM)wnd->extension,0);
  423.     AddAttribute(wnd->MenuBarWnd, VISIBLE);
  424. }
  425.  
  426. /* ----------- Create the status bar ------------- */
  427. static void CreateStatusBar(WINDOW wnd)
  428. {
  429.     if (wnd->StatusBar != NULL)    {
  430.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  431.         wnd->StatusBar = NULL;
  432.     }
  433.     if (TestAttribute(wnd, HASSTATUSBAR))    {
  434.         wnd->StatusBar = CreateWindow(STATUSBAR,
  435.                             NULL,
  436.                             GetClientLeft(wnd),
  437.                             GetBottom(wnd),
  438.                             1,
  439.                             ClientWidth(wnd),
  440.                             NULL,
  441.                             wnd,
  442.                             NULL,
  443.                             0);
  444.         AddAttribute(wnd->StatusBar, VISIBLE);
  445.     }
  446. }
  447.  
  448. #ifdef INCLUDE_MULTI_WINDOWS
  449. /* -------- return the name of a document window ------- */
  450. static char *WindowName(WINDOW wnd)
  451. {
  452.     if (GetTitle(wnd) == NULL)    {
  453.         if (GetClass(wnd) == DIALOG)
  454.             return ((DBOX *)(wnd->extension))->HelpName;
  455.         else 
  456.             return "Untitled";
  457.     }
  458.     else
  459.         return GetTitle(wnd);
  460. }
  461.  
  462. /* ----------- Prepare the Window menu ------------ */
  463. void PrepWindowMenu(void *w, struct Menu *mnu)
  464. {
  465.     WINDOW wnd = w;
  466.     struct PopDown *p0 = mnu->Selections;
  467.     struct PopDown *pd = mnu->Selections + 2;
  468.     struct PopDown *ca = mnu->Selections + 13;
  469.     int MenuNo = 0;
  470.     WINDOW cwnd;
  471.     mnu->Selection = 0;
  472.     oldFocus = NULL;
  473.     if (GetClass(wnd) != APPLICATION)    {
  474.         oldFocus = wnd;
  475.         /* ----- point to the APPLICATION window ----- */
  476.         if (ApplicationWindow == NULL)
  477.             return;
  478.         cwnd = FirstWindow(ApplicationWindow);
  479.         /* ----- get the first 9 document windows ----- */
  480.         while (cwnd != NULL && MenuNo < 9)    {
  481.             if (GetClass(cwnd) != MENUBAR &&
  482.                     GetClass(cwnd) != STATUSBAR) {
  483.                 /* --- add the document window to the menu --- */
  484.                 strncpy(Menus[MenuNo]+4, WindowName(cwnd), 20);
  485.                 pd->SelectionTitle = Menus[MenuNo];
  486.                 if (cwnd == oldFocus)    {
  487.                     /* -- mark the current document -- */
  488.                     pd->Attrib |= CHECKED;
  489.                     mnu->Selection = MenuNo+2;
  490.                 }
  491.                 else
  492.                     pd->Attrib &= ~CHECKED;
  493.                 pd++;
  494.                 MenuNo++;
  495.             }
  496.             cwnd = NextWindow(cwnd);
  497.         }
  498.     }
  499.     if (MenuNo)
  500.         p0->SelectionTitle = "~Close all";
  501.     else
  502.         p0->SelectionTitle = NULL;
  503.     if (MenuNo >= 9)    {
  504.         *pd++ = *ca;
  505.         if (mnu->Selection == 0)
  506.             mnu->Selection = 11;
  507.     }
  508.     pd->SelectionTitle = NULL;
  509. }
  510.  
  511. /* window processing module for the More Windows dialog box */
  512. static int WindowPrep(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  513. {
  514.     switch (msg)    {
  515.         case INITIATE_DIALOG:    {
  516.             WINDOW wnd1;
  517.             WINDOW cwnd = ControlWindow(&Windows,ID_WINDOWLIST);
  518.             int sel = 0;
  519.             if (cwnd == NULL)
  520.                 return FALSE;
  521.             wnd1 = FirstWindow(ApplicationWindow);
  522.             while (wnd1 != NULL)    {
  523.                 if (wnd1 != wnd && GetClass(wnd1) != MENUBAR &&
  524.                         GetClass(wnd1) != STATUSBAR)    {
  525.                     if (wnd1 == oldFocus)
  526.                         WindowSel = sel;
  527.                     SendMessage(cwnd, ADDTEXT,
  528.                         (PARAM) WindowName(wnd1), 0);
  529.                     sel++;
  530.                 }
  531.                 wnd1 = NextWindow(wnd1);
  532.             }
  533.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  534.             AddAttribute(cwnd, VSCROLLBAR);
  535.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  536.             break;
  537.         }
  538.         case COMMAND:
  539.             switch ((int) p1)    {
  540.                 case ID_OK:
  541.                     if ((int)p2 == 0)
  542.                         WindowSel = SendMessage(
  543.                                     ControlWindow(&Windows,
  544.                                     ID_WINDOWLIST),
  545.                                     LB_CURRENTSELECTION, 0, 0);
  546.                     break;
  547.                 case ID_WINDOWLIST:
  548.                     if ((int) p2 == LB_CHOOSE)
  549.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  550.                     break;
  551.                 default:
  552.                     break;
  553.             }
  554.             break;
  555.         default:
  556.             break;
  557.     }
  558.     return DefaultWndProc(wnd, msg, p1, p2);
  559. }
  560.  
  561. /* ---- the More Windows command on the Window menu ---- */
  562. static void MoreWindows(WINDOW wnd)
  563. {
  564.     if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  565.         ChooseWindow(wnd, WindowSel);
  566. }
  567.  
  568. /* ----- user chose a window from the Window menu
  569.         or the More Window dialog box ----- */
  570. static void ChooseWindow(WINDOW wnd, int WindowNo)
  571. {
  572.     WINDOW cwnd = FirstWindow(wnd);
  573.     while (cwnd != NULL)    {
  574.         if (GetClass(cwnd) != MENUBAR &&
  575.                 GetClass(cwnd) != STATUSBAR)
  576.             if (WindowNo-- == 0)
  577.                 break;
  578.         cwnd = NextWindow(cwnd);
  579.     }
  580.     if (cwnd != NULL)    {
  581.         SendMessage(cwnd, SETFOCUS, TRUE, 0);
  582.         if (cwnd->condition == ISMINIMIZED)
  583.             SendMessage(cwnd, RESTORE, 0, 0);
  584.     }
  585. }
  586.  
  587. /* ----- Close all document windows ----- */
  588. static void CloseAll(WINDOW wnd, int closing)
  589. {
  590.     WINDOW wnd1, wnd2;
  591.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  592.     wnd1 = LastWindow(wnd);
  593.     while (wnd1 != NULL)    {
  594.         wnd2 = PrevWindow(wnd1);
  595.         if (GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)    {
  596.             ClearVisible(wnd1);
  597.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  598.         }
  599.         wnd1 = wnd2;
  600.     }
  601.     if (!closing)
  602.         SendMessage(wnd, PAINT, 0, 0);
  603. }
  604.  
  605. #endif    /* #ifdef INCLUDE_MULTI_WINDOWS */
  606.  
  607. static void DoWindowColors(WINDOW wnd)
  608. {
  609.     WINDOW cwnd;
  610.     InitWindowColors(wnd);
  611.     cwnd = FirstWindow(wnd);
  612.     while (cwnd != NULL)    {
  613.         DoWindowColors(cwnd);
  614.         if (GetClass(cwnd) == TEXT && GetText(cwnd) != NULL)
  615.             SendMessage(cwnd, CLEARTEXT, 0, 0);
  616.         cwnd = NextWindow(cwnd);
  617.     }
  618. }
  619.  
  620. /* ----- set up colors for the application window ------ */
  621. static void SelectColors(WINDOW wnd)
  622. {
  623.     if (RadioButtonSetting(&Display, ID_MONO))
  624.         cfg.mono = 1;
  625.     else if (RadioButtonSetting(&Display, ID_REVERSE))
  626.         cfg.mono = 2;
  627.     else
  628.         cfg.mono = 0;
  629.     cfg.snowy = CheckBoxSetting(&Display, ID_SNOWY);
  630.     get_videomode();
  631.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  632.         cfg.mono = 1;
  633.  
  634.     if (cfg.mono == 1)
  635.         memcpy(cfg.clr, bw, sizeof bw);
  636.     else if (cfg.mono == 2)
  637.         memcpy(cfg.clr, reverse, sizeof reverse);
  638.     else
  639.         memcpy(cfg.clr, color, sizeof color);
  640.     DoWindowColors(wnd);
  641. }
  642.  
  643. /* ---- select screen lines ---- */
  644. static void SelectLines(WINDOW wnd)
  645. {
  646.     cfg.ScreenLines = 25;
  647.     if (isEGA() || isVGA())    {
  648.         if (RadioButtonSetting(&Display, ID_43LINES))
  649.             cfg.ScreenLines = 43;
  650.         else if (RadioButtonSetting(&Display, ID_50LINES))
  651.             cfg.ScreenLines = 50;
  652.     }
  653.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  654.         int FullScreen = WindowHeight(wnd) == SCREENHEIGHT;
  655.         SetScreenHeight(cfg.ScreenLines);
  656.         if (FullScreen || SCREENHEIGHT-1 < GetBottom(wnd))
  657.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  658.                 SCREENHEIGHT-1);
  659.     }
  660. }
  661.  
  662. /* ---- set the screen height in the video hardware ---- */
  663. static void SetScreenHeight(int height)
  664. {
  665.     if (isEGA() || isVGA())    {
  666.         SendMessage(NULL, SAVE_CURSOR, 0, 0);
  667.         switch (height)    {
  668.             case 25:
  669.                 Set25();
  670.                 break;
  671.             case 43:
  672.                 Set43();
  673.                 break;
  674.             case 50:
  675.                 Set50();
  676.                 break;
  677.             default:
  678.                 break;
  679.         }
  680.         SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  681.         SendMessage(NULL, RESET_MOUSE, 0, 0);
  682.         SendMessage(NULL, SHOW_MOUSE, 0, 0);
  683.     }
  684. }
  685.  
  686. #ifdef INCLUDE_WINDOWOPTIONS
  687.  
  688. /* ----- select the screen texture ----- */
  689. static void SelectTexture(void)
  690. {
  691.     cfg.Texture = CheckBoxSetting(&Display, ID_TEXTURE);
  692. }
  693.  
  694. /* -- select whether the application screen has a border -- */
  695. static void SelectBorder(WINDOW wnd)
  696. {
  697.     cfg.Border = CheckBoxSetting(&Display, ID_BORDER);
  698.     if (cfg.Border)
  699.         AddAttribute(wnd, HASBORDER);
  700.     else
  701.         ClearAttribute(wnd, HASBORDER);
  702. }
  703.  
  704. /* select whether the application screen has a status bar */
  705. static void SelectStatusBar(WINDOW wnd)
  706. {
  707.     cfg.StatusBar = CheckBoxSetting(&Display, ID_STATUSBAR);
  708.     if (cfg.StatusBar)
  709.         AddAttribute(wnd, HASSTATUSBAR);
  710.     else
  711.         ClearAttribute(wnd, HASSTATUSBAR);
  712. }
  713.  
  714. /* select whether the application screen has a title bar */
  715. static void SelectTitle(WINDOW wnd)
  716. {
  717.     cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
  718.     if (cfg.Title)
  719.         AddAttribute(wnd, HASTITLEBAR);
  720.     else
  721.         ClearAttribute(wnd, HASTITLEBAR);
  722. }
  723.  
  724. #endif
  725.  
  726.